package com.cdc.retrofit;

import com.cdc.retrofit.fastjson.FastJsonConverterFactory;
import com.cdc.urls.Constants;
import retrofit2.Retrofit;
/**
 * Created by cdc on 2018/4/25.
 */

public class RetrofitManager{
    private volatile static RetrofitManager retrofitManager;
    private Retrofit retrofit;

    //无参的单利模式
    public static RetrofitManager getSingleton() {
        if (retrofitManager == null) {
            synchronized (RetrofitManager.class) {
                retrofitManager = new RetrofitManager();
            }
        }
        return retrofitManager;
    }


    //无参的构造方法
    private RetrofitManager() {
        initRetrofitManager();
    }

    //构造方法创建Retrofit实例
    private void initRetrofitManager() {
        retrofit = new Retrofit.Builder().baseUrl(Constants.IP)
                .addConverterFactory(FastJsonConverterFactory.create())
                .build();
    }

    public Api apiservice() {
        return retrofit.create(Api.class);
    }
}
